#ifndef __PLANE_H__
#define __PLANE_H__

#include "Vector3.h"

class Plane{
 public:
	Vector3 normal,point;
	float d;

 Plane()  : normal(0,0,0), point(0,0,0), d(0) { }

	void initialize_from_points(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3) {
		Vector3 aux1, aux2;

		aux1 = v1 - v2;
		aux2 = v3 - v2;

		normal = aux2 * aux1;
		normal.normalize();
		
		point.copy(v2);

		d = -(normal.innerProduct(point));
	}

	void setNormalAndPoint(const Vector3 &normal, const Vector3 &point) {
		this->normal.copy(normal);
		this->normal.normalize();
		d = -(this->normal.innerProduct(point));
	}

	double distance(const Vector3 &p) {
		return (d + normal.innerProduct(p));
	}
	
	void print() {
		std::cout << "Point: " << std::endl;
		point.print(); std::cout << std::endl;
		std::cout << "Normal: " << std::endl;
		normal.print(); std::cout << std::endl;
		
	}

 private:

};


#endif
